<?php

namespace app\api\controller;

use addons\epay\library\Service;
use app\admin\model\goods\Order;
use app\common\controller\Api;
use app\common\controller\Payment;
use app\common\model\FishingGroundOrdersGroups;
use think\Controller;
use think\Db;
use think\Request;


class Usermoneylog extends Api
{
    private static $model;
//    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';


    public function __construct(Request $request = null)
    {
        parent::__construct($request);
        self::$model = new \app\common\model\UserMoneyLog();
    }

    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function lists()
    {
        $pageSize = input('pagesize', 15);
        $userId = $this->auth->id;

        // type为1表示消费，为2表示充值，为3表示收益，为4表示提现
        $type = input('type', 1);
        if (!in_array($type, [1, 2, 3, 4])) {
            $this->error('参数非法！');
        }

        switch ($type) {
            case 1:
                $where = [
                    'user_id' => $userId,
                    'relation_type' => $type
                ];
                $lists = self::$model->where($where)->order('createtime desc')->paginate($pageSize);
                if ($lists) {
                    $hours = config('site.apply_hours');
                    foreach ($lists as $val) {
                        $oInfo = \app\common\model\FishingGroundOrders::find($val->relation_id);
                        $positionId = FishingGroundOrdersGroups::where('order_id', $oInfo->id)->where('user_id', $userId)->value('position_id');
                        $fishsId = \app\common\model\FishingGroundPositions::where('id', $positionId)->value('fishs_id');
                        $groundId = \app\common\model\FishingGroundFishs::where('id', $fishsId)->value('ground_id');
                        $groundName = \app\common\model\FishingGround::where('id', $groundId)->value('name');
                        $val->ground_name = $groundName;

                        $hour = $hours[$oInfo->time_id];
                        $val->remark = '预约钓场' . $hour . '小时';
                    }
                }
                break;
        }

        $this->success('消费记录', $lists);
    }
}
